package com.nccsjz.back.leaveword.web;

import java.sql.SQLException;
import java.util.List;

import com.nccsjz.back.leaveword.service.LeavewordService;
import com.nccsjz.base.BaseAction;
import com.nccsjz.pojo.Leaveword;
import com.nccsjz.utils.Pager;

public class LeavewordAction extends BaseAction {
	
	private Leaveword lv;
	
	private long id;
	
	private long[] ids;//处理全选
	
	private int state=1;//留言状态。0＝未审核，1＝已审核，2＝已回复
	
	
	public int getState() {
		return state;
	}


	public void setState(int state) {
		this.state = state;
	}


	public long[] getIds() {
		return ids;
	}


	public void setIds(long[] ids) {
		this.ids = ids;
	}


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}

	//存放分页信息
    private Pager pager;
    //页码
    private int pageNo=1;
    //每页多少行
    private int pageSize=5;
	
	private boolean f;
	
	private LeavewordService service;

	
	public Pager getPager() {
		return pager;
	}


	public void setPager(Pager pager) {
		this.pager = pager;
	}


	public int getPageNo() {
		return pageNo;
	}


	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public Leaveword getLv() {
		return lv;
	}


	public void setLv(Leaveword lv) {
		this.lv = lv;
	}


	public String add_Lv() throws SQLException{
		service=new LeavewordService();
		if(service.addLv(lv)){
		this.addActionMessage("留言成功！");
		}else{
			this.addActionMessage("留言失败！");
		}
		return "success";
	}
/**
 * 前台
 * @return
 * @throws SQLException
 */
	public String list_Lv() throws SQLException{
		service=new LeavewordService();
		pager=service.getLvs(pageSize, pageNo,1);
		return "list";
	}
	/**
	 * 后台显示list
	 * @return
	 * @throws SQLException
	 */
	public String listview_Lv() throws SQLException{
		service=new LeavewordService();		
		pager=service.getLvs(pageSize, pageNo,state);
		return "listview";
	}
	
	/**
	 * 查看单个留言
	 * @return
	 * @throws SQLException
	 */
	public String view_Lv() throws SQLException{
		service=new LeavewordService();	
		lv=service.getLeavewordById(id);
		return "view";
	}
	/**
	 * 保存留言
	 * @return
	 * @throws SQLException 
	 */
	public String save_Lv() throws SQLException{
		service=new LeavewordService();	
		if(service.saveLv(lv)){
			this.addActionMessage("修改成功！");
		}else{
		     this.addActionMessage("修改失败！");
		}
		return "review";
	}
	/**
	 * 删除留言
	 * @throws SQLException 
	 */
	public String del_Lv() throws SQLException{
		service=new LeavewordService();	
		if(service.deleteLvByID(id)){
			this.addActionMessage("删除成功！");
		}else{
			this.addActionMessage("删除失败！");
		}
		return "review";
	}
	/**
	 * 删除全选或选中的留言
	 * @throws SQLException 
	 */
	public String delAll_Lv() throws SQLException{
		service=new LeavewordService();	
		if(service.delAll(ids)){
			this.addActionMessage("删除成功！");
		}
		return "review";
	}

}
